qui(
    function (require, exports, module) {
        Specimen.Grid = function (options) {
            this.dao = Specimen.Dao;
            this.config = Specimen.Config;
            this.options = options || {};
        };
        Com.inherits(Specimen.Grid, Ancestor.Grid).extend({
            // specimen_list.html start
            runList: function () {
                var self = this;
                self.$grid = self.options.$grid;
                self.$downloadGrid = self.options.$downloadGrid;
                self.initListGrid();
                self.initDownloadListGrid();
                self.initDlg();
                self.config.PageBeanSpecimen = Specimen.Util.createPageBean();
                self.config.PageBeanSpecimen.setNewData([], 40);
                self.config.PageBeanDownload = Specimen.Util.createPageBean();
                self.config.PageBeanDownload.setNewData([], 40);
                self.query();
            },

            initListGrid: function (options, callback) {
                var self = this;
                var gridConfig = self.getGridConfig(self.config.TABLE_LIST);
                options = $.extend(true, {}, gridConfig, options);
                self.$grid.jqGrid(options);
            },
            initDownloadListGrid: function (options, callback) {
                var self = this;
                var gridConfig = self.getGridConfig(self.config.TABLE_DOWNLOAD_LIST);
                options = $.extend(true, {}, gridConfig, options);
                self.$downloadGrid.jqGrid(options);
                $("#dowloadpage_left").css({width: "10px"})
            },
            initDlg: function () {
                $("#downloadDiv").dialog({
                        title: "样本下载",
                        autoOpen: false,
                        width: 700,
                        height: 540,
                        modal: true,
                        dialogClass: 'alert',
                        resizable: false
                    }
                )
                $(".ui-dialog-titlebar-close").html('<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">close</span>');
            },
            query: function () {
                var self = this;
                self.$grid.setGridParam({page: 1, url: Specimen.urlConfig.getSpecimenListUrl, loadtext: '加载中...',
                    datatype: "json", loadui: "block"}).trigger("reloadGrid");
            },
            // specimen_list.html end
            // specimen_host_frame.html start
            hostRun: function () {
                var self = this;
                self.config.PageBeanSpecimen = new Specimen.Util.createPageBean();
                self.config.PageBeanSpecimen.setNewData([], 40);
                var element = Specimen.Util.getAlbumDataByUrl()
                self.fillHostAlbumData(element);
                self.initHostFrame();
                Specimen.Util.doQueryShot();
            },
            fillHostAlbumData: function (element) {
                var parent = $("#sportContainer");
                parent.find("span[name=news_name]").html(element.news_name);
                parent.find("span[name=album_name]").html(element.album_name);
                parent.find("span[name=album_id]").html(element.album_id);
                parent.find("span[name=qipu_id]").html(element.qipu_id);
                parent.find("span[name=channel_name]").html(element.channel);
            },
            initHostFrame: function () {
                $("#imageZone").on("click", "img", function (e) {
                    var $target = $(e.target);
                    console.log($target.attr("id"));
                    if ($target.hasClass("select-img")) {
                        $target.removeClass("select-img");
                        $target.parent().children().last().remove();
                    } else {
                        $target.addClass("select-img");
                        $target.parent().append($(Specimen.Config.HOST_SIGN));
                    }
                })
                $("button[name=btn_submit]").bind("click", function (e) {
                    if ($("#imageZone img").length == 0) {
                        return;
                    }
                    if ($("img.select-img").length == 0) {
                        SystemDialog.queryConfirm("本次未标注图像,是否确认提交?", function (flag) {
                            if (flag) {
                                Specimen.Util.submitSelectedHost();
                            }
                        })
                    } else {
                        Specimen.Util.submitSelectedHost();
                    }
                })
                $("button[name=btn_goback]").bind("click", function (e) {
                    Specimen.Util.goBackToList("退出");
                })
            }
        })
    }
);